function compose(...funcs) {
  return function (args) {
    return funcs.reverse().reduce((result, fn) => {
      return fn(result);
    }, args);
  };
}

const funcs = [
  (num) => {
    return num + 1;
  },
  (num) => {
    return num + 2;
  },
  (num) => {
    return num + 3;
  },
  (num) => {
    return num + 4;
  },
];

console.log(compose(...funcs)(0));
